import type { App } from 'vue'
import { createRouter, createWebHashHistory } from 'vue-router'
import { RoutePath } from '../enums/route'

function getRoutes() {
  return Object
    .values(import.meta.glob('../routes/*.ts', { eager: true }))
    .map((route: any) => route.default)
    .flat()
}

export const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: RoutePath.home,
    },
    ...getRoutes(),
  ],
})

export function install(app: App) {
  app.use(router)
}
